package com.hzhjhh.view.manageView.menus.accountMng.login;

import java.util.Objects;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import com.hzhjhh.entity.UserInfo;
import com.hzhjhh.mapper.UserInfoMapper;
import com.hzhjhh.means.Select_Means;
import com.hzhjhh.util.DBUtils;
import com.hzhjhh.view.manageView.menus.accountMng.Adminstrator;
import com.hzhjhh.view.manageView.menus.accountMng.RegisterDialog;

/**
 * 菜单栏初始化-仓库-账户管理-添加/修改用户-管理员登录弹出框-登录按钮
 * 
 * @author 12083
 *
 */
public class LoginBt {

	private static UserInfoMapper userInfoMapper;

	/**
	 * 按钮
	 */
	public static JButton btInit(Adminstrator adminstrator) {
		JButton login = new JButton();
		login.setBounds(81, 202, 83, 25);
		login.setText("登录");
		userInfoMapper = DBUtils.getSqlSession(true).getMapper(UserInfoMapper.class);

		login.addActionListener(event -> {
			String name = adminstrator.getTxfName().getText();
			String password = adminstrator.getPfPassword().getText();
//			Vector user = new Vector();
//			user = Select_Means.Select_User(name, password);
			UserInfo userInfo = userInfoMapper.selectByLoginInfo(name, password, "超级管理员");
			if (Objects.nonNull(userInfo)) {
				adminstrator.setVisible(false);// 验证通过隐藏当前窗口
				RegisterDialog dlogen = new RegisterDialog();
				dlogen.setVisible(true);// 弹出注册窗口
				dlogen.setTitle("注册用户");

			} else {
				JOptionPane.showMessageDialog(adminstrator, "用户名或密码不正确,请重新输入", "错误", JOptionPane.ERROR_MESSAGE);
				return;
			}
		});
		return login;
	}
}
